package com.transaction.common.util;

import java.util.Random;

public class ChinaUtil {

    /**
     * 生成汉字
     * @Title: creatChinese
     * @author: dy.yin 2021/8/19 14:21
     */
    public static String GenerateChinese(){
        Random random = new Random();

        int highPos = (176 + Math.abs(random.nextInt(39)));//获取高位值
        int lowPos = (161 + Math.abs(random.nextInt(93)));//获取低位值

        byte[] b = new byte[2];

        b[0] = (new Integer(highPos).byteValue());
        b[1] = (new Integer(lowPos).byteValue());

        String str = null;//转成中文
        try {
            str = new String(b, "GBk");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }


    /**
     * 生成姓名
     * @Title: GenerateName
     * @author: dy.yin 2021/8/19 14:24
     * @return: java.lang.String
     */
    public static String generatePerSonName(){
        String[] familyNames = ConstUtil.FAMILY_NAMES.split(",");
        String lastName = familyNames[new Random().nextInt(familyNames.length)];
        StringBuilder name = new StringBuilder(lastName);
        int num = new Random().nextInt(2) + 1;
        for(int i = 0;i < num;i++){
            name.append(GenerateChinese());
        }
        return name.toString();
    }


    /**
     * 生成公司名称
     * @Title: generateCompanyName
     * @author: dy.yin 2021/9/28 8:59
     * @return: java.lang.String
     */
    public static String generateCompanyName() {
        StringBuilder name = new StringBuilder();
        for(int i = 0;i < 6;i++){
            name.append(GenerateChinese());
        }
        String suffixName = ConstUtil.COMPANY_SUFFIX[new Random().nextInt(ConstUtil.COMPANY_SUFFIX.length)];
        name.append(suffixName);
        return name.toString();
    }
}
